package com.crm.kz.menu;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;
import com.crm.kz.R;
import com.crm.kz.common.BaseFragment;
import com.crm.kz.common.GlobalVariable;
import com.crm.kz.common.SystemConfig;
public class LoginFragment extends BaseFragment {

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.login, container, false);
        titleBar.setVisibility(View.GONE);

        EditText user =  view.findViewById(R.id.systemUser);
        user.setText(GlobalVariable.user);
        EditText password =  view.findViewById(R.id.password);
        password.setText(GlobalVariable.password);
        EditText serverAddress =  view.findViewById(R.id.systemAddress);
        serverAddress.setText(GlobalVariable.serverAddress);
        Button button = view.findViewById(R.id.systemSave);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GlobalVariable.user = String.valueOf(user.getText());
                GlobalVariable.password = String.valueOf(password.getText());
                GlobalVariable.serverAddress = String.valueOf(serverAddress.getText());
                SystemConfig.setConfig(getContext());
                MenuFragment menuFragment = MenuFragment.newInstance();
                FragmentManager fm = getActivity().getSupportFragmentManager();
                fm.beginTransaction()
                        .replace(R.id.fragment_container, menuFragment)
                        .commit();
            }
        });
        return view;
    }

}
